/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session.stateless;

import entity.SalesLeadEntity;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import type.UserTitle;

/**
 *
 * @author Andy
 */
@Stateless
@LocalBean
public class SalesLeadSessionBean {
    
    @PersistenceContext
    private EntityManager em;
    SalesLeadEntity salesLead;
    Date dateJoined = new Date();
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    public SalesLeadSessionBean() {
    }
    
    public void addNewSalesLead(String companyName, String jobTitle, String firstName, String lastName, UserTitle title){
        salesLead = new SalesLeadEntity();
        salesLead.setCompanyName(companyName);
        salesLead.setJobTitle(jobTitle);
        salesLead.setFirstName(firstName);
        salesLead.setLastName(lastName);
        salesLead.setTitle(title);
        
        //salesLead.setDateJoined(dateJoined);
        em.persist(salesLead);
    }
    
    public List<SalesLeadEntity> getAllSalesLeads(){
        
        Query query = em.createQuery("SELECT s FROM salesLead s");
        return query.getResultList();
        
    }
    
    
     public SalesLeadEntity getSalesLeadById(Long id) {
        return em.find(SalesLeadEntity.class, id);
    }
    
}
